package com.xhxi.photobooker.websocket;

import jakarta.websocket.*;
import jakarta.websocket.server.ServerEndpoint;
import org.springframework.stereotype.Component;

@ServerEndpoint("/testws")
@Component
public class TestWsEndpoint {
    
    @OnOpen
    public void onOpen(Session session) {
        System.out.println("[TestWsEndpoint] onOpen 被调用! Session ID: " + session.getId());
        System.out.println("[TestWsEndpoint] 请求参数: " + session.getRequestParameterMap());
    }

    @OnMessage
    public void onMessage(String message, Session session) {
        System.out.println("[TestWsEndpoint] 收到消息: " + message);
        try {
            session.getBasicRemote().sendText("服务器收到消息: " + message);
        } catch (Exception e) {
            System.err.println("[TestWsEndpoint] 发送消息失败: " + e.getMessage());
        }
    }

    @OnClose
    public void onClose(Session session) {
        System.out.println("[TestWsEndpoint] onClose 被调用! Session ID: " + session.getId());
    }

    @OnError
    public void onError(Session session, Throwable error) {
        System.err.println("[TestWsEndpoint] 发生错误! Session ID: " + session.getId());
        error.printStackTrace();
    }
} 